home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / root.loc < prev    next >
Internet Message Format  |  1995-03-23  |  11KB

  1. From helens!shelby!rutgers!rochester!pt.cs.cmu.edu!andrew.cmu.edu!paul+ Fri Jul 20 12:50:21 PDT 1990
  2. Article 2178 of comp.sys.handhelds:
  3. Path: helens!shelby!rutgers!rochester!pt.cs.cmu.edu!andrew.cmu.edu!paul+
  4. >From: paul+@andrew.cmu.edu (Paul J. Dujmich)
  5. Newsgroups: comp.sys.handhelds
  6. Subject: Root Locus Routines
  7. Message-ID: <oadmM3y00Uh-01JUVs@andrew.cmu.edu>
  8. Date: 20 Jul 90 15:40:51 GMT
  9. Organization: Computing Systems, Carnegie Mellon, Pittsburgh, PA
  10. Lines: 343
  11.  
  12.  
  13. I wrote the following 2 small routines this term for my control systems
  14. class. The programs calculate the exit point of complex roots from
  15. the real axis, and the entry point for complex roots to the real axis,
  16. for Root Locus plots. "Exit" finds the point on the real axis where gain (K)
  17. is maximum. At this point a pair of complex roots leave the real axis.
  18. "Entry" finds the point on a real axis line segment where gain (K) is minimum.
  19. It is at this point that a complex root pair enter the real axis line segment.
  20.  
  21. Paul
  22. pauld@fs1.ece.cmu.edu
  23. Dept. of Electrical and Computer Engineering
  24. Carnegie-Mellon University
  25. Pittsburgh, PA.
  26. -------------------------------------------------------------------------------
  27. %%HP: T(3)A(R)F(.);
  28. @ PROGRAM NAME:    EXIT
  29. @ DATE:            7-19-90
  30. @ PURPOSE:         Calculate the breakaway point for complex roots from real
  31. @                  axis, for Root Locus analysis.
  32. @ ARGUMENTS:       Level 4: 'Algebraic expression in terms of "S"'(Capital S)
  33. @                  Level 3: Left limit of real axis line segment
  34. @                  Level 2: Right limit of real axis line segment
  35. @                  Level 1: Desired accuracy (ex: .0001)
  36.  
  37. \<<
  38. \-> fs ll rl a    @load in function (as algebraic object in terms of "S"),
  39.   \<<             @ left limit, right limit, accuracy
  40.       0
  41.       'tstk'
  42.       STO         @clear the Point and K variables
  43.       0
  44.       'pt'
  45.       STO
  46.  
  47. @************************ Main DO loop **************************************
  48.       DO
  49.          ll
  50.          rl
  51.          -
  52.          2
  53.          /
  54.          'hs'   @calculate half the real line segment length
  55.          STO
  56.  
  57.          hs
  58.          rl
  59.          +
  60.          'tp'
  61.          STO    @tp = center between left and right line limits
  62.          hs
  63.          2
  64.          /
  65.          tp
  66.          +
  67.          'tp1'
  68.          STO     @find left half test point ,half way between left limit and tp
  69.  
  70.          tp1
  71.          'S'
  72.          STO
  73.          'fs' EVAL
  74.          ABS
  75.          MINV
  76.          'tp1k'
  77.          STO        @find K at left half test point
  78.  
  79.          hs
  80.          2
  81.          /
  82.          rl
  83.          +
  84.          'tp2'
  85.          STO      @find the right half test point, between tp and right limit
  86.  
  87.          tp2
  88.          'S'
  89.          STO
  90.          'fs'  EVAL
  91.          ABS
  92.          MINV
  93.          'tp2k'
  94.          STO        @find K at right half test point
  95.  
  96.  
  97.  
  98.          IF 'tp1k > tp2k' @left half of line segment has bigger K value
  99.              THEN  tp
  100.                    'rl'
  101.                    STO      @ tp is new right limit
  102.                    tstk
  103.                    'oldk'   @save old K value from last pass
  104.                    STO
  105.                    tp1k     @left test point has larger K value
  106.                    'tstk'
  107.                    STO      @save the K value
  108.                    pt
  109.                    'opt'    @save old point value from last pass
  110.                    STO
  111.                    tp1      @left test point produces largest K value
  112.                    'pt'     @save the left half point value
  113.                    STO
  114.  
  115.              ELSE  tp       @right half of line segment has larger K value
  116.                    'll'
  117.                    STO      @tp is now new left limit
  118.                    tstk
  119.                    'oldk'   @save old K value from last pass
  120.                    STO
  121.                    tp2k
  122.                    'tstk'
  123.                    STO      @right half line segment has larger K value
  124.                    pt
  125.                    'opt'    @save point value from last pass
  126.                    STO
  127.                    tp2      @save right half point value
  128.                    'pt'
  129.                    STO
  130.          END
  131.  
  132.  
  133.  
  134.  
  135.       tstk         @calculate difference in K between last pass and this pass
  136.       oldk
  137.       -
  138.       'dif'        @save it
  139.       STO
  140.  
  141.  
  142.       UNTIL  dif 0 <  dif a \<= OR     @run DO loop until the difference
  143.       END                              @between this pass K value and the K
  144.                                        @value from the last pass is negative
  145.                                        @(K value started to decrease) or
  146.                                        @run DO loop until the difference
  147.                                        @between 2 successive passes produced
  148.                                        @K values that differed by less than
  149.                                        @the required accuracy value.
  150.  
  151. @************************ end main DO loop ***********************************
  152. IF 'dif < 0 '                       @K value started to decrease
  153.     THEN opt                        @we want the Point and K value from the
  154.          'loc'                      @last pass
  155.          STO
  156.          oldk
  157.          'val'
  158.          STO
  159.     ELSE pt                         @we want the Point and K value from this
  160.          'loc'                      @pass (required accuracy has been met)
  161.          STO
  162.          tstk
  163.          'val'
  164.          STO
  165. END
  166.  
  167.  
  168.  
  169. @Print the results on LCD screen
  170. CLLCD
  171. "Breakaway Point = "
  172. 1 DISP
  173. loc \->STR
  174. 2 DISP
  175. "K at Breakaway Point"
  176. 4 DISP
  177. val \->STR
  178. 5 DISP
  179. 7 FREEZE
  180.  
  181.  
  182. @Nuke all the variables
  183. {val loc dif opt pt oldk tp2k tp2 tp1k tp1 tp hs tstk S}
  184. PURGE
  185. CLEAR                              @clean off stack
  186. fs                                 @leave the function on the stack in level 1
  187. \>>                                @in case user wants to do another line
  188. \>>                                @segment
  189.  
  190. -------------------------------------------------------------------------------
  191. %%HP: T(3)A(R)F(.);
  192. @ PROGRAM NAME:    ENTRY
  193. @ DATE:            7-19-90
  194. @ PURPOSE:         Calculate the entry point for complex roots to real
  195. @                  axis, for Root Locus analysis.
  196. @ ARGUMENTS:       Level 4: 'Algebraic expression in terms of "S"'(Capital S)
  197. @                  Level 3: Left limit of real axis line segment
  198. @                  Level 2: Right limit of real axis line segment
  199. @                  Level 1: Desired accuracy (ex: .0001)
  200.  
  201. \<<
  202. \-> fs ll rl a    @load in function (as algebraic object in terms of "S"),
  203.   \<<             @ left limit, right limit, accuracy
  204.       1E400
  205.       'tstk'
  206.       STO         @clear the Point and K variables
  207.       0
  208.       'pt'
  209.       STO
  210.  
  211. @************************ Main DO loop **************************************
  212.       DO
  213.          ll
  214.          rl
  215.          -
  216.          2
  217.          /
  218.          'hs'   @calculate half the real line segment length
  219.          STO
  220.  
  221.          hs
  222.          rl
  223.          +
  224.          'tp'
  225.          STO    @tp = center between left and right line limits
  226.  
  227.  
  228.          hs
  229.          2
  230.          /
  231.          tp
  232.          +
  233.          'tp1'
  234.          STO     @find left half test point ,half way between left limit and tp
  235.  
  236.          tp1
  237.          'S'
  238.          STO
  239.          'fs' EVAL
  240.          ABS
  241.          MINV
  242.          'tp1k'
  243.          STO        @find K at left half test point
  244.  
  245.          hs
  246.          2
  247.          /
  248.          rl
  249.          +
  250.          'tp2'
  251.          STO      @find the right half test point, between tp and right limit
  252.  
  253.          tp2
  254.          'S'
  255.          STO
  256.          'fs'  EVAL
  257.          ABS
  258.          MINV
  259.          'tp2k'
  260.          STO        @find K at right half test point
  261.  
  262.  
  263.  
  264.          IF 'tp1k < tp2k'   @left half of line segment has smaller K value
  265.              THEN  tp
  266.                    'rl'
  267.                    STO      @ tp is new right limit
  268.                    tstk
  269.                    'oldk'   @save old K value from last pass
  270.                    STO
  271.                    tp1k     @left test point has smaller K value
  272.                    'tstk'
  273.                    STO      @save the K value
  274.                    pt
  275.                    'opt'    @save old point value from last pass
  276.                    STO
  277.                    tp1      @left test point produces smallest K value
  278.                    'pt'     @save the left half point value
  279.                    STO
  280.                @tp2k < tp1k
  281.              ELSE  tp       @right half of line segment has smallest K value
  282.                    'll'
  283.                    STO      @tp is now new left limit
  284.                    tstk
  285.                    'oldk'   @save old K value from last pass
  286.                    STO
  287.                    tp2k
  288.                    'tstk'
  289.                    STO      @right half line segment has smallest K value
  290.                    pt
  291.                    'opt'    @save point value from last pass
  292.                    STO
  293.                    tp2      @save right half point value
  294.                    'pt'
  295.                    STO
  296.          END
  297.  
  298.  
  299.  
  300.  
  301.       oldk         @calculate difference in K between last pass and this pass
  302.       tstk         @(we expect tstk to normally be smaller than oldk)
  303.       -
  304.       'dif'        @save it
  305.       STO
  306.  
  307.  
  308.       UNTIL  dif 0 <  dif a \<= OR     @run DO loop until the difference
  309.       END                              @between this pass K value and the K
  310.                                        @value from the last pass is negative
  311.                                        @(K value started to increase) or
  312.                                        @run DO loop until the difference
  313.                                        @between 2 successive passes produced
  314.                                        @K values that differed by less than
  315.                                        @the required accuracy value.
  316.  
  317. @************************ end main DO loop ***********************************
  318. IF 'dif < 0 '                       @K value started to increase
  319.     THEN opt                        @we want the Point and K value from the
  320.          'loc'                      @last pass
  321.          STO
  322.          oldk
  323.          'val'
  324.          STO
  325.     ELSE pt                         @we want the Point and K value from this
  326.          'loc'                      @pass (required accuracy has been met)
  327.          STO
  328.          tstk
  329.          'val'
  330.          STO
  331. END
  332.  
  333.  
  334.  
  335. @Print the results on LCD screen
  336. CLLCD
  337. "Entry Point = "
  338. 1 DISP
  339. loc \->STR
  340. 2 DISP
  341. "K at Entry Point"
  342. 4 DISP
  343. val \->STR
  344. 5 DISP
  345. 7 FREEZE
  346.  
  347.  
  348. @Nuke all the variables
  349. {val loc dif opt pt oldk tp2k tp2 tp1k tp1 tp hs tstk S}
  350. PURGE
  351. CLEAR                              @clean off stack
  352. fs                                 @leave the function on the stack in level 1
  353. \>>                                @in case user wants to do another line
  354. \>>                                @segment
  355.  
  356.  
  357.